package server

import (
	v1 "proxy_manage/gen/proxy/v1/v1connect"
	"proxy_manage/internal/conf"
	"proxy_manage/internal/service"
	"proxy_manage/transport/connect"

	"github.com/go-kratos/kratos/v2/log"
)

func NewConnectServer(c *conf.Server, proxy *service.ProxyService, logger log.Logger) *connect.Server {
	var ops []connect.ServerOption
	if c.Connect.Network != "" {
		ops = append(ops, connect.Network(c.Connect.Network))
	}
	if c.Connect.Addr != "" {
		ops = append(ops, connect.Address(c.Connect.Addr))
	}
	if c.Connect.Timeout != nil {
		ops = append(ops, connect.Timeout(c.Connect.Timeout.AsDuration()))
	}
	svc := connect.NewServer(ops...)
	path, handler := v1.NewProxyServiceHandler(proxy)
	svc.Handle(path, handler)

	return svc
}
